//////////////////////////////////////////////////////////////////////////

#ifndef _RESEARCH_H_
#define _RESEARCH_H_

//////////////////////////////////////////////////////////////////////////

#ifndef _RESULTSTABLE_H_
#include "resultstable.h"
#endif

#include <vector>
#include <QString>

//////////////////////////////////////////////////////////////////////////

/** Class for patient research
*
*  @author  Anastasia Karpinska
*  @author  Roman Pasechnik
*  @since   Oct 17th, 2009
*  @updated Oct 23th, 2009
*/

class Research
{
//////////////////////////////////////////////////////////////////////////

public:

//////////////////////////////////////////////////////////////////////////


    /** Constructor */
    Research( const QString& _date, const ResultsTable& _resTable = ResultsTable() );


    /** Returns date of the research */
    const QString& GetDate() const;


    /** Returns research results */
    const ResultsTable& GetResultsTable() const;


    /** Adds research data */
    void AddData( unsigned char _data, size_t _count );


    /** Calculates research results */
    void Calculate();


//////////////////////////////////////////////////////////////////////////

private:

//////////////////////////////////////////////////////////////////////////


    /** Position of patient feet */
    struct FeetPosition
    {
    //////////////////////////////////////////////////////////////////////

        /** Right heel is down */
        bool m_RightHeelDown;

        /** Left heel is down */
        bool m_LeftHeelDown;

        /** Right toe is down */
        bool m_RightToeDown;

        /** Left toe is down */
        bool m_LeftToeDown;

        /** Duration of this position */
        size_t m_Duration;

    //////////////////////////////////////////////////////////////////////
    };


    /** [Utility type]: array of FeetPositions */
    typedef std::vector<FeetPosition> ResearchData;


    /** All data, gathered during this research */
    ResearchData m_ResearchData;


    /** Date of the research */
    QString m_Date;


    /** Research results */
    ResultsTable m_Results;


//////////////////////////////////////////////////////////////////////////


    /** Kills first step */
    void KillFirstStep();


    /** Returns position where first step begins and determines if patient
        started from left foot or right */
    size_t GetFirstStep( bool& _isFirstLeft ) const;


    /** If patients right foot is up (doesn't touch the ground) */
    bool IsRightUp( size_t _position ) const;


    /** If patients left foot is up (doesn't touch the ground) */
    bool IsLeftUp( size_t _position ) const;


    /** If patients left foot is up (doesn't touch the ground) */
    void CalculateTimes( size_t _steps );


//////////////////////////////////////////////////////////////////////////
};

//////////////////////////////////////////////////////////////////////////

#endif

//////////////////////////////////////////////////////////////////////////
